import {
  listAllTableColumn,
  listAllTableColumn4Office,
  getPageData,
  queryAllExportData,
  batchDeleteData,
  oneClickDeleteData,
  insertOfficeInfo,
  deleteById,
  getOfficePageData,
  queryAllOfficeExportData,
  findDataById,
  findOfficeDataById,
  updateRecord, execFileParse
} from "@/services/detaileddatareportingApi";

export default {
  namespace: 'detaileddatareporting',


  state: {
    // 详情数据上报
    data: {
      list: [],
      pagination: {},
    },
    // 详情数据正式库
    data2: {
      list: [],
      pagination: {},
    },
  },

  effects: {
    *getPageData({ payload }, { call, put }) {
      const response = yield call(getPageData, payload);
      yield put({
        type: 'cb4getPageData',
        payload: response,
      });
    },

    /**
     * 获取table的columns
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *listAllTableColumn({ payload }, { call, put }) {
      const response = yield call(listAllTableColumn, payload);
      return response;
    },

    /**
     * 获取table的columns
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *listAllTableColumn4Office({ payload }, { call, put }) {
      const response = yield call(listAllTableColumn4Office, payload);
      return response;
    },

    /**
     * 点击导出列表信息
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *queryAllExportData({ payload }, { call, put }) {
      const response = yield call(queryAllExportData, payload);
      return response;
    },

    /**
     * 批量删除
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *batchDeleteData({ payload }, { call, put }) {
      const response = yield call(batchDeleteData, payload);
      return response;
    },

    /**
     * 一键删除
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *oneClickDeleteData({ payload }, { call, put }) {
      const response = yield call(oneClickDeleteData, payload);
      return response;
    },

    /**
     * 点击详细数据存入正式库
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *insertOfficeInfo({ payload }, { call, put }) {
      const response = yield call(insertOfficeInfo, payload);
      return response;
    },

    /**
     * 点击删除单条数据
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *deleteById({ payload }, { call, put }) {
      const response = yield call(deleteById, payload);
      return response;
    },

    *getOfficePageData({ payload }, { call, put }) {
      const response = yield call(getOfficePageData, payload);
      yield put({
        type: 'cb4getOfficePageData',
        payload: response,
      });
    },

    /**
     * 详细数据正式库  点击导出列表信息
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *queryAllOfficeExportData({ payload }, { call, put }) {
      const response = yield call(queryAllOfficeExportData, payload);
      return response;
    },

    /**
     * 详细数据正式库  点击查看单条信息
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *findDataById({ payload }, { call, put }) {
      const response = yield call(findDataById, payload);
      return response;
    },

    /**
     * 详细数据正式库  编辑  点击查看单条信息
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *findOfficeDataById({ payload }, { call, put }) {
      const response = yield call(findOfficeDataById, payload);
      return response;
    },

    /**
     * 更新数据
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *updateRecord({ payload }, { call, put }) {
      const response = yield call(updateRecord, payload);
      return response;
    },

    /**
     * 图像文件解析
     * @param payload
     * @param call
     * @param put
     * @returns {Generator<*, *, *>}
     */
    *execFileParse({ payload }, { call, put }) {
      const response = yield call(execFileParse, payload);
      return response;
    },
  },


  reducers: {
    cb4getPageData(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
    cb4getOfficePageData(state, action) {
      return {
        ...state,
        data2: action.payload.data,
      };
    },
  },
};
